import re
from pathlib import Path
from utils.right_index import right_index


class DataProcess:
    def __init__(self):
        # 医用术语库
        self.del_text_reg = self.load_data(Path(__file__).parent / 'utils/医用术语.txt')
        # 服务术语
        self.del_service_text_reg = self.load_data(Path(__file__).parent / 'utils/服务术语.txt')
        # 医疗服务词汇
        self.service_text = self.load_data(Path(__file__).parent / 'utils/医疗服务特有词汇.txt')
        # 基本医用术语库
        self.del_normal_text_reg2 = self.load_data(Path(__file__).parent / 'utils/基本医用术语库.txt')

        # 去除基础术语
        self.large_name = "((?<!及)其他门急诊费用|其他门诊收费|卫生材料费?用?(检验费)?|一般治疗操作费|其他住院费用?|其他门急诊费|实验室诊断费|" + \
                          "医疗总费用|中药饮片费?用?|中药饮品费?用?|中成药费?用?|中草药费?用?|其他费用?|其他收入|分币误差|其它收入|手术费用?|" + \
                          "治疗费用?|西药费?用?|材料费用?|草药费用?|放射费用?|化验费用?|检查费用?|检验费用?|其他费|住院费用?|处置费用?|麻醉费用?" + \
                          "|放射线|精度费|理疗费用?|体检费用?|疫苗费用?|洗牙费用?|牙修复费用?|配镜费用?)"

        self.del_normal_text_reg = re.compile(
            f"^\(*{self.large_name}\)*|\(*{self.large_name}\)*$|"
            r"#*[(.\\/医]?(?<![鳖龟])甲[类S]?(?![蓝氨胺奥苯变部测常成床丹地等淀碘噁肥粉酚封肝功钴管硅化花环磺基亢抗壳兰乐雷力流硫螺麻那萘哌旁"
            r"疱配片泼浅强羟羥庆氰巯软麝肾术舒双司素酸胎碳肟细纤酰限硝型癣氧医吲治酯状唑])([0-9]+%?)?[.\\/)]?|"
            r"\(?[乙甲]+限\)?|"
            r"[(.\\/]?甲(?=强)(?!强龙)([0-9]+%?)?[.\\/)]?|"
            r"[.\\/(医]?乙[类S]?(?![限进胺酰烯醇苯基氨醛酚型二吗哌肝检稀氧拉派奎乳醒状红精神碘流己剑聚])([0-9]+%?)?[.\\/)]?|"
            r"[.\\/(医]?丙[类S]?(?![酚磺咪瑞转雌酮醇茶型稀肾美戊电素搽氨泊托肝卡葡泽硫嗪哌通甲谷烯林帕孕酸沙])([0-9]+%?)?[.\\/)]?|"
            r"[.\\/(]?中?[上国省市县村非g]?(?<![伯氨])基(?![本托丁丙去末胶葡连础层强底转肾干脲薄地因二酸糖注细肽夹药合比氯金泰体质纤酯酚端素孕酪台淀酶超价半己四维])[.\\/)]?|"
            r"[.\\/(]?(无痛)?自费?(?![愿氧身制描贴主非负条做评毁链觉体交免缠热血发产动助第凝定测调煎排杀我粘酸锁风然维])[.\\/)]?|"
            r"[.\\/(]?付(?![方肾茄])[.\\/)]?|"
            r"(?<![耐威收合最日酸脂部胰术量苏张血化中层染感性备含腔副期安种瓷管括州及声正科加型潘达动地脉超混清万肝力内德描用体特国速])[.\\/()价]?高[.\\/)(]|"
            r"^带[一二三四五六]?(?![针毛线涂蒂环])|"
            r"^市(?![场])|"
            r"^单位|"
            r"[.\\/()]?非?医保[.\\/)(]?|[.\\/()无]?明细[.\\/)(]?|\(省采([0-9]+.)?[0-9]\)|\(4\+7.*?\)|\(案\d\)|"
            "国药.字[A-Z][0-9]{1,8}|国械备[0-9]{1,8}|津卫财[0-9]+文?件?|中国基[0-9]*|"
            "\(曾用名.*?\)|\(原名.*?\)|含材料费[0-9]*元?|小计:?([0-9]+.)?[0-9]*元?|最多不超过[0-9]+元|医保付([0-9]+.)?[0-9]*元|"
            "\(10%\)(?![浓])|\d+%价|特需|\(特\)|^其中-?|统筹|^\(外\)|集采\d+|Y:\(\d+%\)|"
            "\((GD\d?|SJ|GC\d?|gc\d?|BD|JH|KL|kl|H|J|j|K|M|S|T|Y|G|g|C|B)\)|(KF)$|^Y(?![a-zA-Z型染])")

        # 特殊符号
        self.del_symbol_reg = re.compile(r"[ ▪■□█★●○⊙◎◇◆Δ△▲▼�♀♂＠@!！$￥＆&＾^?§№☆※→←↑↓°☉①②③④⑤⑥•˙∙·®`ω┏├└┌√┗⊕≈¤]|(\\/)")
        # 单位 耗材相关 cm|CM|厘米|mm|MM|毫米|英寸|分钟|m|M|米|
        self.unit = "(C㎡|剂次|喷雾|号楼|GB|TB|gb|tb|ml|mL|ML|毫升|mg|MG|毫克|ug|μg|微克|ng|纳克|IU|iu|kiu|单位|kBq|cm|CM|厘米|mm|MM|毫米|英寸|分钟|" + \
                    "[sSμg克KkGuUm米支揿掀崭只付副例个包丸层号楼套箱批头份盒喷根片袋板张枚粒瓶次帖贴剂年万元])"
        # 去规格
        self.units = re.compile(f"(?<![BbDlLgGμUuQqmM0-9第于含过收锝*xX/:每≥Ｑ])(([GJY\-])*(规格:)*([0-9]+\.)*[0-9]*"
                                f"([*xX/:每]*([0-9]+\.)*[0-9]+ ?{self.unit})+"
                                f"([*xX/:每]*([0-9]+\.)*[0-9]* ?{self.unit}*)*)(?![AC-Za-z0-9%.])(?!\(含)|"

                                "(?<![BbDlLgGμUuQqmM0-9第于含过收锝*xX/:每≥Ｑ])(([GJY\-])*(规格:)*([0-9]+\.)*[0-9]*"
                                f"([xX/:每]+([0-9]+\.)*[0-9]* ?{self.unit})+"
                                f"([*xX/:每]*([0-9]+\.)*[0-9]* ?{self.unit}*)*)(?![AC-Za-z0-9%.])(?!\(含)|"

                                f"\(([0-9]+\.)*[0-9]* ?{self.unit}\)|"

                                "(规格:)*(?<![0-9*])(?<!片\()(([0-9]+\.)*[0-9]+[\+\-\*xX/]([0-9]+\.)*[0-9]+)(?![吋寸电.笔0-9])|"
                                "\((?<![0-9a-zA-Z])\d+[.:]\d+(?! ?[0-9a-zA-Z%])\)*|\(\d*\)|"
                                f"\({self.unit}\)|(?<=[达])袋$|"
                                f"(相当于饮片|相当于原药)([0-9]+\.)?[0-9]* ?{self.unit}*([*xX/:每]*([0-9]+\.)?[0-9]* ?{self.unit}*)*"
                                )
        # 去市
        with open(Path(__file__).parent / 'utils/市.txt', "r") as f:
            citys = f.readlines()
        citys.sort(key=lambda x: len(x), reverse=True)
        citys = ["\(" + i.strip() + "市?" for i in citys]

        self.special_char1 = re.compile("|".join(citys))
        self.special_char2 = re.compile("\(广州\)|\(广\)|"
                                        "\(扬州\)|\(扬\)|\(苏州\)|\(杭州\)|\(杭\)|"
                                        "\(石家庄\)|\(邯郸\)|"
                                        "沈阳$|"
                                        "\(青岛\)|"
                                        "\(无锡\)|"
                                        "\(开封\)|"
                                        "\(哈尔滨\)|"
                                        "\(长春\)|"
                                        "\(江苏常州\)|"
                                        "\(漳州\)|"
                                        "\(深圳\)|"
                                        "\(增城\)|"
                                        "\(厦门\)|"
                                        "\(南京\)|"
                                        "\(成都\)|\(成\)|"
                                        "\(合肥\)|\(合\)|"
                                        "\(宜昌\)|"
                                        "\(常州\)|\(常\)|"
                                        "\(岳阳\)|"
                                        "\(武汉\)|"
                                        "\(东北\)|"
                                        "\(东莞\)|"
                                        "\(济南\)|"
                                        "\(石家庄\)|"
                                        "新昌县?|"
                                        "长春(?!新碱)")
        # 去省
        self.special_char3 = re.compile(
            "北京市?|\(京\)|\(北\)|"
            "天津市?|\(津\)|"
            "河北省?|\(冀\)|"
            "山西省?|\(晋\)|"
            "内蒙古自治区|内蒙古|内蒙|\(蒙\)|"
            "辽宁省?|\(辽\)|"
            "吉林省?|\(吉\)|"
            "黑龙江省?|\(黑\)|"
            "上海市?|\(沪\)|"
            "江苏省?|\(苏\)|"
            "浙江省?|\(浙\)|"
            "安徽省?|\(皖\)|"
            "福建省?|\(闽\)|"
            "江西省?|\(赣\)|"
            "山东省?|\(鲁\)|"
            "河南省?|\(豫\)|"
            "湖北省?|\(鄂\)|"
            "湖南省?|\(湘\)|"
            "广东省?|\(粤\)|"
            "广西壮族自治区|\(桂\)|"
            "海南省?|\(琼\)|"
            "四川省?|\(川\)|"
            "贵州省?|\(贵\)|"
            "(云南省?|\(云\))(?!白)|"
            "重庆市?|\(渝\)|"
            "西藏自治区|\(藏\)|"
            "陕西省?|\(陕\)|"
            "甘肃省?|\(甘\)|"
            "青海省?|\(青\)|"
            "宁夏回族自治区|\(宁\)|"
            "新疆维吾尔自治区|\(新\)|"
            "香港特别行政区|\(港\)|"
            "澳门特别行政区|\(澳\)|"
            "台湾省?|\(台\)|NULL"
        )
        # 其他去除
        self.other_char = re.compile(
            # 去开头
            r"^[、#*),.:%/_\-+]+|"
            "^t?D[2(]|^\+7|^(ZOK|GJS|JTY|JYX|gcj|gc\d|[dLv0-9]?JY|JS|GJ|GA|G\*|GY|JG|JH|JS|JP|GC|S\*|SO|SC|gc|KL|DG|DL|dl|"
            "[βPYSsEOWμ](?=[\u4e00-\u9fa5])(?![型染])|"
            "[JHEGTZzjKMFQABD](?![ABDFOPRSTUu])|\d{6,}|C(?=[\u4e00-\u9fa5()])(?![一反型类等级肽]))|"
            "^\(*(ZOK|d|[LZXRFxz0-9]{1,3}(?![层瓶线])|[0-9]{4,})\)*(?=[\u4e00-\u9fa5()])(?![岁人碳碘周岁超混小)])|"
            "^\(*[自基集带国进市新限警危高看听似急选兴儿非药费]{1,3}\)*(?![\u4e00-\u9fa5])|"
            "^省(?![国级、优])|^国大|^[A-Za-z0-9]{4,}型|"

            "^(\([大小镜法封量干临绿美盟散省舒西延中天豁金谈省优][g0-9]*\))|"
            "^[片](?![夹姜断费])(?=.)|"
            "^\([01].0\)|"

            # 去结尾
            r"[、*.:/_\-#+Ω><]+$|"
            "\(*(?<![0-9一二三四五六七八九十])[/每]?(人?次|根管|项)\)*$|"
            "(?<=囊)板$|"
            "(?<=[\u4e00-\u9fa5) ])((0\.)?0+|外科|国家\)*|中国大?|\([直]\)|-\d|\(\d|\(*\d+[.*#]\)*|"
            "(?<![片和定钙素])\(*[*ABGHJKDLMSUTYjlkxyzrW/]+\d*(?![类])\)*|(?<![迪诺氨己法])[自基集国采进市新限警危高看听似急选儿非]+|"
            "\(*(?<![艾恒欧易弥恩可善雅澜奈斯诺高泰川林化])[珍易威欧贝培齐广德优谈省重农]+\)*|"
            "\(*(?<![现博思巴欧南诊郁尤合若押内])金\)*|"
            "\(*(?<![黑量人蛋中薤])白\)*|"
            "\(*(?<![英盖锆肢安保])全\)*|"
            "(?<=液)合|X|\(整\)|(?<=[定 ])F|(?<=[钳件 ])[0-9a-zA-Z\-.]+|(?<=[药 ])N|"
            "#\d+|\d{6,}|嘎嘎|英寸)$|"

            r"[;'\"=~|#]|"
            r"\*(?=[\u4e00-\u9fa5])|"
            r"\(?([一二三、]*级|(县级|非)?公立|城市三级甲等)?医院\)?(?!床)|"
            r"[(\-.,、_\\/#]+\)*$|(?<![钠M片定F层])\([a-zA-GJ-Z]{1,3}\)$|\.无$|"
            "^金贵(?=(大枣))|(?<=片)(?<!胶片)\(*[*%a-zA-HJ-QS-Z0-9]+\)*(\.[0-9]+)?(?![射线])|(?<=钠)[0-9]+(?=注)|"
            "(?<![0-9:αCc白Kk])1(?![:人0-9%.bQqT抗小β])|"
            "(?<=.)(?<![0-9a-zA-Z和维素\-γδ])[ABGHJKLMSUYjlkx](?![a-zA-Z蛋和族型等级细超普类12\-])|(?<=[片])\d+%|"
            "(?<=[\u4e00-\u9fa5)])(?<![素])\d+(?=\))|"
            "(?<![0-9A-Za-z])[﹥＜＞≤≥](?![0-9A-Za-z])|"
            "[2]0[0-2][0-9]-[01][0-9]-[0-3][0-9]|"  # 日期格式
            "CO(?=复方)|片(?=片)" # 甲方反馈特殊
        )

    def load_data(self, path):
        with open(path, "r") as f:
            del_list = f.readlines()
        del_list = [i.strip() for i in del_list]
        del_list = list(set(del_list))
        del_list.sort(key=lambda x: len(x), reverse=True)
        # 调试用,不提交
        with open(path, "w") as f:
            f.writelines([word + "\n" for word in del_list])

        for i, w in enumerate(del_list):
            w = w.replace("(", "\(")
            w = w.replace(".", "\.")
            del_list[i] = w.replace(")", "\)")
        return re.compile("|".join(del_list))

    def del_normal_shuyu(self, word):
        word = re.sub(self.del_normal_text_reg, "", word)
        return re.sub(self.del_normal_text_reg2, "", word)

    def del_shuyu(self, word):
        # 去空括号
        word = re.sub("\( *\)|< *>", "", word)
        word = re.sub(self.del_text_reg, "", word)
        return self.del_normal_shuyu(word)

    def del_symbol(self, word):
        word = re.sub(self.del_symbol_reg, " ", word)
        return word.strip()

    def del_units(self, word):
        word = re.sub(self.units, "", word)
        # finded_word = re.search(self.units, word)
        # if finded_word:
        #     finded_word = finded_word.group()
        #     print(finded_word, file=open("utils/规格.txt", "a"))
        word = re.sub("\( *\)|< *>", "", word)
        return word

    def del_citys(self, word):
        word = re.sub("(?<=[!-.\"\'()=:+~*#%,/_;])、", "", word)
        word = re.sub(self.special_char1, "", word)
        word = re.sub(self.special_char2, "", word)
        return re.sub(self.special_char3, "", word)

    def del_others(self, word):
        return re.sub(self.other_char, "", word)

    # 括号匹配,去除重复
    def check_parentheses(self, word):
        word = re.sub("(?<=[()]) | (?=[()])", "", word)
        stack = []
        area = []
        k = 0
        for i, w in enumerate(list(word)):
            if w == "(":
                stack.append(i - k)
            if w == ")" and stack:
                area.append((stack[-1], i - k))
                del (stack[-1])
            elif w == ")":
                word = word[:i - k] + " " + word[i - k + 1:]
                # k += 1

        if stack:
            for s in stack:
                word = word[:s] + word[s + 1:]
        if area:
            # 括号前的内容和括号后的内容
            word1 = word[:area[-1][0]] + word[area[-1][1] + 1:]
            # 括号里的内容
            word2 = word[area[-1][0 ] +1:area[-1][1]]
            # 如果括号外的内容多，而且括号内的内容和括号外有重复，取括号外的内容
            if len(word1) >= len(word2) and word2 in word1:
                word = word1
            elif len(word1) <= len(word2) and word1 in word2:
                word = word2
            wordlist = []
            k = 0
            for m, n in area:
                w = word[m - k + 1:n - k]
                if w not in wordlist:
                    wordlist.append(w)
                else:
                    word = word[:m - k] + word[n - k + 1:]
                    k += len(w)
        return word.strip()

    # 仅括号匹配
    def check_parentheses2(self, word):
        # 去括号前后的空格
        word = re.sub("(?<=[()]) | (?=[()])", "", word)
        stack = []
        area = []
        k = 0
        for i, w in enumerate(list(word)):
            if w == "(":
                stack.append(i - k)
            if w == ")" and stack:
                area.append((stack[-1], i - k))
                del (stack[-1])
            elif w == ")":
                word = word[:i - k] + " " + word[i - k + 1:]
                # k += 1

        if stack:
            for s in stack:
                word += ")"
                # word = word[:s] + word[s + 1:]

        # 首尾括号去除
        if (0, len(word ) -1) in area:
            word = word[1:-1]
        # 去多重括号
        if re.search("\(\(.*?\)\)", word):
            word = re.sub("\(\(", "(", word)
            word = re.sub("\)\)", ")", word)
        return word.strip()

    # 统一为英文符号
    def ch_en(self, word):
        # 统一为英文符号
        intab = u"！—。【】“”‘’《》—「」『』〖〗〔〕〓︰﹒﹕﹙﹚﹝﹞﹢〈〉∽∶‥–‒Ι×[]（）＃［］{}：％＊﹛﹜，－／÷＿﹡；ⅹ\\"
        outab = u"!-.()\"\"\'\'()-()()()()=:.:()()+()~::--i*()()#()():%*(),-//_*;*/"
        trantab = str.maketrans(intab, outab)  # 一一映射。
        word = word.translate(trantab)  # 返回字符串S的副本，其中每个字符都已通过给定的转换表进行映射。
        if re.findall("＜.*?＞", word):
            word = word.replace("＜", "(")
            word = word.replace("＞", ")")
        if re.findall("<.*?>", word):
            word = word.replace("<", "(")
            word = word.replace(">", ")")
        return word

    def post_process(self, word):
        # 其他符号
        symbol_char = re.compile("[;'\"=~|]")
        cell = word
        # 统一为英文符号
        cell = self.ch_en(cell)
        # 去特殊符号
        cell = self.del_symbol(cell)
        # 括号匹配, 去多余括号
        cell = self.check_parentheses2(cell)

        # 跳过的条件
        # 字数小于2
        if len(cell) < 2:
            return cell
        # 中草药等
        if re.search("([甲乙丙]类|自费)?中草药(颗粒)?", cell):
            cell = re.sub(symbol_char, "", cell)
            cell = re.sub("\d*%|\d+\.?\d*", "", cell)
            return cell

        # 去基础术语
        cell = self.del_normal_shuyu(cell)
        # 医疗服务
        if re.search(self.service_text, cell):
            # 去其他符号
            cell = re.sub(symbol_char, "", cell)
            # 去地区
            cell = self.del_citys(cell)
            # 去服务术语
            cell = re.sub(self.del_service_text_reg, "", cell)
        # 药品耗材其他
        else:
            # 去规格
            cell = self.del_units(cell)
            # 去其他符号
            cell = re.sub(symbol_char, "", cell)

            # 去医用术语
            cell = self.del_shuyu(cell)
            # 去地区
            cell = self.del_citys(cell)
            # 括号匹配,去重复药品名
            cell = self.check_parentheses(cell)

        # 其他去除
        cell = self.del_others(cell)
        cell = cell.strip()
        cell = self.del_others(cell)
        # 去空括号
        cell = re.sub(r"\(\)|<>", "", cell)
        cell = re.sub(r"%%", "%", cell)
        cell = re.sub(r",,", ",", cell)
        # cell = re.sub(r"[*]", "", cell)
        # 括号匹配, 去多余括号
        cell = self.check_parentheses2(cell)
        # 特殊情况强制修改
        if re.findall("(?<!0\.)9%氯化钠注射液", cell):
            cell = "0.9%氯化钠注射液"
        if "氯化钠针" in cell and "浓氯化钠注射液" in cell and "10%" in cell:
            cell = "浓氯化钠注射液(10%)"
        # 诊查费不去除自费
        if re.search("诊.费", cell) and re.search("(?<!扣除)自费", word):
            cell += "(自费)"
        # 不回传空值，如果结果为空，回传原值
        if not cell:
            return word
        return cell

    def split_parts(self, word):
        parts = dict(
            医用术语="",
            药厂="",
            特殊符号="",
            规格="",
            其他=""
        )

        # 其他符号
        symbol_char = re.compile("[;'\"=~|]")
        cell = word
        # 统一为英文符号
        cell = self.ch_en(cell)
        # 去特殊符号
        tmp = cell
        cell = self.del_symbol(cell)
        parts["特殊符号"] += self.deleted_words(tmp, cell)
        # 括号匹配, 去多余括号
        cell = self.check_parentheses2(cell)

        # 跳过的条件
        # 字数小于2
        if len(cell) < 2:
            return cell, ""
        # 中草药等
        if re.search("([甲乙丙]类|自费)?中草药(颗粒)?", cell):
            cell = re.sub(symbol_char, "", cell)
            cell = re.sub("\d*%|\d+\.?\d*", "", cell)
            return cell, ""

        # 去基础术语
        tmp = cell
        cell = self.del_normal_shuyu(cell)
        parts["医用术语"] += self.deleted_words(tmp, cell)
        # 医疗服务
        if re.search(self.service_text, cell):
            # 去其他符号
            tmp = cell
            cell = re.sub(symbol_char, "", cell)
            parts["特殊符号"] += self.deleted_words(tmp, cell)
            # 去地区
            tmp = cell
            cell = self.del_citys(cell)
            parts["药厂"] += self.deleted_words(tmp, cell)
            # 去服务术语
            tmp = cell
            cell = re.sub(self.del_service_text_reg, "", cell)
            parts["医用术语"] += self.deleted_words(tmp, cell)
        # 药品耗材其他
        else:
            # 去规格
            tmp = cell
            cell = self.del_units(cell)
            parts["规格"] += self.deleted_words(tmp, cell)
            # 去其他符号
            tmp = cell
            cell = re.sub(symbol_char, "", cell)
            parts["特殊符号"] += self.deleted_words(tmp, cell)

            # 去医用术语
            tmp = cell
            cell = self.del_shuyu(cell)
            parts["医用术语"] += " " + self.deleted_words(tmp, cell)
            # 去地区
            tmp = cell
            cell = self.del_citys(cell)
            parts["药厂"] += self.deleted_words(tmp, cell)
            # 括号匹配,去重复药品名
            cell = self.check_parentheses(cell)

        # 其他去除
        cell = self.del_others(cell)
        cell = cell.strip()
        cell = self.del_others(cell)
        # 去空括号
        cell = re.sub(r"\(\)|<>", "", cell)
        cell = re.sub(r"%%", "%", cell)
        cell = re.sub(r",,", ",", cell)
        # cell = re.sub(r"[*]", "", cell)
        # 括号匹配, 去多余括号
        cell = self.check_parentheses2(cell)
        # 特殊情况强制修改
        if re.findall("(?<!0\.)9%氯化钠注射液", cell):
            cell = "0.9%氯化钠注射液"
        if "氯化钠针" in cell and "浓氯化钠注射液" in cell and "10%" in cell:
            cell = "浓氯化钠注射液(10%)"
        # 诊查费不去除自费
        if re.search("诊.费", cell) and re.search("(?<!扣除)自费", word):
            cell += "(自费)"
        parts["其他"] += self.deleted_words(word, cell)
        for k, v in parts.items():
            parts[k] = v.strip()
            if k != "其他":
                for i in re.split("[ ()]", v):
                    if i and i in parts["其他"]:
                        parts["其他"] = parts["其他"].replace(i, "")
                        parts["其他"] = parts["其他"].strip()
        for k, v in parts.items():
            if k != "特殊符号":
                if not re.search("[0-9a-zA-Z\u4e00-\u9fa5]", v):
                    parts[k] = ""

        return cell, parts

    def deleted_words(self, full_name, processed_name):
        try:
            same_words_index, _ = right_index(full_name, processed_name)
        except:
            return ""
        deleted_words_index = [j for j in range(len(full_name)) if j not in same_words_index]
        result = ""
        if deleted_words_index:
            deleted_words = []
            words = ""
            for j, index in enumerate(deleted_words_index):
                word = full_name[index]
                if len(deleted_words_index) < 2:
                    words = word
                    deleted_words.append(words)
                # 拼接连续字符
                if j > 0 and deleted_words_index[j] - deleted_words_index[j - 1] == 1:
                    if words == '':
                        words += full_name[index - 1]
                    words += word
                    if j == len(deleted_words_index) - 1:
                        deleted_words.append(words)
                        words = ''
                elif j > 0:
                    deleted_words.append(words)
                    words = ''

            for del_word in deleted_words:
                if del_word and del_word in full_name:
                    result += " "+del_word
            result = result[1:]
        return result

